﻿using Microsoft.SqlServer.Server;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Input;
using System.Windows.Interactivity;

namespace LoginDemo.ViewModel.Common
{
    public class EventCommand : TriggerAction<DependencyObject>
    {

        public static readonly DependencyProperty CommandProperty =
            DependencyProperty.Register("Command", typeof(ICommand), typeof(EventCommand), new PropertyMetadata(null));

        public static readonly DependencyProperty CommandParameterProperty =
            DependencyProperty.Register("CommandParameter", typeof(object), typeof(EventCommand), new PropertyMetadata(null));
        public object CommandParameter 
        {
            get { return (object)GetValue(CommandParameterProperty); }
            set { SetValue(CommandParameterProperty, value); }
        }

        /// <summary>
        /// 事件
        /// </summary>
        public ICommand Command 
        {
            get 
            {
                return (ICommand)GetValue(CommandProperty);
            }
            set 
            {
                SetValue(CommandProperty, value);
            }
        }
        protected override void Invoke(object paramter) 
        {
            if (CommandParameter != null) 
            {
                paramter = CommandParameter;
            }
            if (Command != null) 
            {
                Command.Execute(paramter);
            }
        }

    }
}
